package com.coldwindblows.blog.controller;

import javax.servlet.http.HttpServletRequest;

import com.coldwindblows.blog.pojo.UserDo;
import com.coldwindblows.blog.utils.MapCache;
import com.coldwindblows.blog.utils.TaleUtils;

/**
 * Created by ColdWindBlows on 2018/07/05
 *
 */
public abstract class BaseController {

	public static String THEME = "themes/default";
	
	protected MapCache cache = MapCache.single();
	
	/**
	 * 主页的页面主题
	 * @param viewName
	 * @return
	 */
	public String render(String viewName) {
		return THEME + "/" + viewName;
	}
	
	public BaseController title(HttpServletRequest request, String title) {
		request.setAttribute("title", title);
		return this;
	}
	
	public BaseController keywords(HttpServletRequest request, String keywords) {
		request.setAttribute("keywords", keywords);
		return this;
	}
	
	/**
	 * 获取请求绑定的登录对象
	 * @param request
	 * @return
	 */
	public UserDo user(HttpServletRequest request) {
		return TaleUtils.getLoginUser(request);
	}
	
	public Integer getUid(HttpServletRequest request) {
		return this.user(request).getUid();
	}
	
	public String render_404() {
		return "comm/error_404";
	}
	
}
